package com.lovedice;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.lovedice.type.Action;

public class DiceForm extends Activity {

	TextView txtNameDiceSide;
	private int id;
	private Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dice_form);
		txtNameDiceSide = (TextView) findViewById(R.id.edittext_dice_side);
		Bundle extras = getIntent().getExtras();
		id = extras.getInt("id");
		txtNameDiceSide.setText( extras.getString("nome") );
		
		((TextView) findViewById(R.id.dice_form_title)).setText((id > 0 ? getResources().getString(R.string.dices_set_edit) : getResources().getString(R.string.dices_set_add) ));
	
		if (extras.getInt("action") == Action.CREATE.getAction() ){
			((TextView) findViewById(R.id.dice_form_subtitle_delete)).setVisibility(Button.GONE);
			((Button) findViewById(R.id.button_delete_dice_side)).setVisibility(Button.GONE);
		}

	}

	public void updateDiceSet(View view){
    	setIntent();
    	setResult(RESULT_OK, this.intent);
    	finish();
    }
	public void deleteDiceSet(View view) {
		setIntent();
		setResult(RESULT_FIRST_USER, this.intent);
		finish();
	}
    public void cancelDiceSet(View view) {
    	setResult(RESULT_CANCELED);
    	finish();
    }
	private void setIntent() {
		String nome = txtNameDiceSide.getText().toString();
    	intent = new Intent();
		intent.putExtra("id", this.id);
    	intent.putExtra("nome", nome);
	}
}
